package com.olympus.hermes.common.support;

import javax.persistence.AttributeConverter;
import java.time.Instant;

/**
 * @author Mickey
 * @since 2021/1/12
 */
public class InstantLongConverter implements AttributeConverter<Instant, Long> {

    @Override
    public Long convertToDatabaseColumn(Instant date) {
        return date == null ? null : date.toEpochMilli();
    }

    @Override
    public Instant convertToEntityAttribute(Long date) {
        return date == null ? null : Instant.ofEpochMilli(date);
    }
}
